<?php $this->_extends('../_layouts/default_layout'); ?>
<?php $this->_block('contents'); ?>
<link type="text/css" href="<?=Q::ini('custom_system/base_url')?>css/jq.autocomplete.css" rel="stylesheet" />
<script type="text/javascript" src="<?=Q::ini('custom_system/base_url')?>js/jq.autocomplete.js"></script>
<script type="text/javascript">
Refresh = function(){
	//jq的自动完成
	$(".ajax_product").autocomplete("<?=url('Storage::Product/ProductInfoAjax')?>").result(function(event, data, formatted){
		if (data[0])
		{
			var container = $(this).parent().parent();
			container.find("input[name^='product_id']").val(data['id']);
			container.find("input[name^='cost_price']").val(data['cost_price']);
		}
	});
};
$(function(){
	var i = 0;
	$("#add_product").click(function(){
		var _html = "<tr>";
		_html += "<td><input type='text' size='60' name='product_number_new" + i + "' class='ajax_product' /><input type='hidden' name='product_id_new" + i + "' /></td>";
		_html += "<td><input type='text' size='8' name='cost_price_new" + i + "' /></td>";
		_html += "<td><input type='text' size='8' name='quantity_new" + i + "' /></td>";
		_html += "<td><a href='javascript:void(0);' class='del_product'>删除产品</a></td>";
		_html += "</tr>";
		$("#list").append(_html);
		Refresh();
		i++;
	});
	$(".del_product").live("click", function(){
		if ( ! confirm("确定删除该产品？"))
		{
			return false;
		}
		else
		{
			$(this).parent().parent().remove();
		}
	});
	Refresh();
})

</script>
<form method="post" action="<?=url('Storage::OtherIO/OutEditSave')?>">
<input type="hidden" name="other_io_id" value="<?=$other_io['id']?>" />
<table class="form_table">
<tr>
	<th>出库单号</th>
	<td><?=$other_io['number']?></td>
</tr>
<tr>
	<th>经手人员</th>
	<td>
		<select name="user_id">
			<?foreach ($user as $u):?>
			<option value="<?=$u['id']?>" <?if($u['id']==CURRENT_USER_ID)echo "selected='selected'"?>><?=$u['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>选择仓库</th>
	<td>
		<select name="warehouse_id" id="warehouse">
			<?foreach ($warehouse as $w):?>
			<option value="<?=$w['id']?>" <?if($other_io['warehouse_id'] == $w['id'])echo "selected='selected'"?>><?=$w['name']?></option>
			<?endforeach;?>
		</select>
	</td>
</tr>
<tr>
	<th>备注</th>
	<td><textarea name="notes" cols="50" rows="2"><?=$other_io['notes']?></textarea></td>
</tr>
</table>
<table width="80%" class="list_table"  id="list">
<tr>
	<th width="400">产品编号</th>
	<th width="80">单位成本</th>
	<th width="80">数量</th>
	<th width="100">操作</th>
</tr>
<?foreach ($item as $i):?>
<tr>
	<td><input type="text" size="60" name="product_number_<?=$i['id']?>" class="ajax_product" value="<?=$i['product_number']?> <?=$i['product_name']?>" /><input type="hidden" name="product_id_<?=$i['id']?>" value="<?=$i['product_basic_id']?>" /></td>
	<td><input type="text" size="8" name="cost_price_<?=$i['id']?>" value="<?=$i['cost_price']?>" disabled="disabled" /></td>
	<td><input type="text" size="8" name="quantity_<?=$i['id']?>" class="blur" value="<?=$i['quantity']?>" /></td>
	<td><a href="javascript:void(0);" class="del_product">删除产品</a></td>
</tr>
<?endforeach;?>
</table>
<a id="add_product">添加出库单产品</a>
<div align="center"><input type="submit" class="button" value="确认" /><input type="hidden" name="<?=Q::ini('unique_token_name');?>" value="<?=Helper_BSS_Normal::genToken();?>"/></div>
</form>
<?php $this->_endblock();?>